<template>
  <div>
    <div v-if="!phonenumber" class="py-10 bold">
      请在基本资料模块补充手机号码
    </div>
    <div v-else>
      <div class="flex">
        <img :src="qrCodeData" alt="QR Code" />
        <div class="ml-25px mt-20px">
          <div>设置公众号消息步骤：</div>
          <p>1、请先填写基础资料中的手机号码</p>
          <p>2、扫码获取授权信息</p>
          <p>3、点击测试发送</p>
          <p>
            若要关闭推送：公众号设置界面-通知消息管理-系统单据处理通知-设置为关闭
          </p>
        </div>
      </div>
      <div class="ml-14px">
        <el-button type="primary" @click="testFn()">测试发送</el-button>
        <span class="text-#f00">{{ testMsg }}</span>
      </div>
    </div>
  </div>
</template>
<script setup>
import { handWxtask } from '@/api/otherBusinesses'
import qrcode from 'qrcode'
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
const phonenumber = computed(() => {
  return userStore.userInfo.phonenumber
})
let qrCodeData = ref('') //二维码信息
let testMsg = ref('') //测试发送 显示的信息
onMounted(() => {
  //替换为你需要生成二维码的数据
  let redirect_url =
    import.meta.env.VITE_GZH_URL +
    '/accessingPages?type=officialAccount&phone=' +
    phonenumber.value
  const qrCodeDatas =
    'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa32b339d60658a59&redirect_uri=' +
    encodeURIComponent(redirect_url) +
    '&response_type=code&scope=snsapi_base&state=1,0#wechat_redirect'
  qrcode.toDataURL(qrCodeDatas, (err, url) => {
    if (err) {
      console.error(err, '222222')
    } else {
      qrCodeData.value = url
      console.log(qrCodeDatas, '---')
    }
  })
})
//测试发送
const testFn = async () => {
  let params = {
    receiver: userStore.userInfo.userId,
    sendTime: '2023-01-01 12:01:01',
    sender: '张三',
    serviceType: '1'
  }
  let res = await handWxtask(params)
  testMsg.value = res.msg
  console.log(res, 'params--')
}
</script>
<style scoped lang="scss"></style>
